//
//  testUpdateCoins.c
//  dominion
//
//  Created by Doug Mason on 3/8/14.
//  Copyright (c) 2014 Doug Mason. All rights reserved.
//

#include <stdio.h>
#include "testUpdateCoins.h"

int testUpdateCoins(int player, struct gameState* state, int bonus){
    int numErrors = 0;
    int updateResult;
    int postCoins = 0;
    int i;
    for (i = 0; i < state->handCount[player]; i++) {
        if(state->hand[player][i] == copper){
            postCoins+=1;
        }
        else if(state->hand[player][i]==silver){
            postCoins+=2;
        }
        else if(state->hand[player][i]==gold){
            postCoins+=3;
        }
    }
    postCoins+=bonus;
    updateResult = updateCoins(player,state,bonus);
    if(updateResult != 0 ){
        printf("updateCoins did not return successfully!\n");
        numErrors+=1;
    }
    if(postCoins!=state->coins){
        printf("updateCoins did not correctly! it returned %d, however it should be %d\n",state->coins,postCoins);
        numErrors+=1;
    }
    if(numErrors == 0){
    //All's well that ends well
        printf("All tests passed for updateCoins\n");
        return 0;
    }
    //oops, failed tests
    else{
        printf("Tests failed for updateCoins: %d\n",numErrors);
        state->coins=postCoins;
        return -1;
    }
}
